import { isUndefined, trimStart } from 'lodash';

// 请求过滤参数处理
export const getFilterString = (
  params: { [x: string]: string },
  fuzzyMatchKeys = ['name', 'app', 'label', 'annotation']
) =>
  Object.keys(params)
    .filter((key) => !isUndefined(params[key]) && params[key] !== '')
    .map((key) =>
      fuzzyMatchKeys.includes(key) && !/\|/g.test(params[key])
        ? `${key}~${trimStart(params[key])}`
        : `${key}=${trimStart(params[key])}`
    )
    .join(',');
